var templateParams = {
    tableTheads:["步骤名称", "序号", "类型", "逻辑控制", "关键字","元素/用例片段","测试数据", "输出数据"
        , "预期结果", "创建时间", "创建人", "备注", "操作"],
    btnTools:[{
        type:"primary",
        size:"M",
        id:"add-object",
        iconFont:"&#xe600;",
        name:"新增测试步骤"
    },{
        type:"danger",
        size:"M",
        id:"batch-op",
        iconFont:"&#xe6bf;",
        name:"批量操作"
    },{
        type:"danger",
        size:"M",
        id:"setting-step-order",
        iconFont:"&#xe6f3;",
        name:"步骤排序"
    }],
    formControls:[{
        edit:true,
        label:"ID",
        objText:"idText",
        input:[{
            hidden:true,
            name:"id"
        }]
        },
        {
            required:true,
            label:"步骤名称",
            input:[{
                name:"step_name"
            }]
        },
        {
            edit:true,
            label:"序号",
            objText:"seq_numText",
        },
        {
            required:true,
            label:"类型",
            select:[{
                name:"type",
                option:function(){
                    let options = [];
                    $.each(DICT_CONFIG.step_type, function(k, v){
                        options.push({value: v, text: v});
                    });

                    return options;
                }()
            }]
        },
        {
            label:"用例片段",
            objText:"snippet_nameText",
            input:[{
                name:"snippet_id",
                hidden:true
            },{
                name:"snippet_setting",
                hidden:true
            }],
            button:[{
                style:"success",
                value:"选择",
                name:"choose-snippet"
            },{
                style:"primary",
                value:"配置",
                name:"setting-snippet"
            },{
                style:"danger",
                value:"清除",
                name:"clear-choose-snippet"
            }]
        },
        {
            required:true,
            label:"关键字",
            select:[{
                name:"keyword_id",
                option:function(){
                    let options = [];
                    $.each(DICT_CONFIG.keyword, function(i, n){
                        $.each(n, function(i1, n1){
                            options.push({value: n1.id, text: n1.cn_name});
                        });
                        return false;
                    });
                    return options;
                }()
            }]
        },
        {
            label:"元素对象",
            objText:"element_nameText",
            input:[{
                name:"element_id",
                hidden:true
            }],
            button:[{
                style:"success",
                value:"选择",
                name:"choose-element"
            },{
                style:"danger",
                value:"清除",
                name:"clear-choose-element"
            }]
        },
        {
            label:"逻辑控制",
            select:[{
                name:"control_id",
                option:function(){
                    let options = [{value: '', text: '无'}];
                    $.each(DICT_CONFIG.step_control, function(i, n){
                        options.push({value: n.id, text: n.cn_name});
                    });

                    return options;
                }()
            }]
        },
        {
            label:"测试数据",
            input:[{
                name:"default_data",
                hidden: true
            }],
            button:[{
                style:"primary",
                value:"配置",
                name:"setting-default-data"
            }]
        },
        {
            label:"输出数据",
            input:[{
                name:"export_data",
                hidden: true
            }],
            button:[{
                style:"primary",
                value:"配置",
                name:"setting-export-data"
            }]
        },
        {
            label:"预期结果",
            input:[{
                name:"expected_result",
                hidden: true
            }],
            button:[{
                style:"primary",
                value:"配置",
                name:"setting-expected-result"
            }]
        },
        {
            label:"备注",
            textarea:[{
                name:"mark"
            }]
        },
        {
            name: "case_id"
        }
    ]};

var columnsSetting = [
    {
        "data":null,
        "width": 30,
        "render":function(data, type, full, meta){
            return checkboxHmtl(data.step_name, data.id, "selectStep");
        }},
    {
        "data":"id",
        "width": 50,
    },
    {"data":"step_name", "width":"15%"},
    {
        "data": "seq_num",
        "width": 45
    },
    {"data":"type", "width":55, "className":"ellipsis"},
    {"data":"control", "width":55},
    {"data":"keyword", "width":55},
    {
        "data": null,
        "className":"ellipsis",
        "render": function(data, type, full, meta){
            let name = 'snippet' == data.type ? data.snippet_name : data.element_name;
            return CONSTANT.DATA_TABLES.COLUMNFUN.ELLIPSIS(name);
        }
    },
    ellipsisSettingData('default_data', 'setting-default-data'),
    ellipsisSettingData('export_data', 'setting-export-data'),
    ellipsisSettingData('expected_result', 'setting-expected-result'),
    ellipsisData("create_time"),
    ellipsisData("creator_name"),
    // ellipsisData("alter_time"),
    // ellipsisData("last_mender_name"),
    longTextData("mark", "step_name", "备注信息"),
    {
        "data":null,
        "render":function(data, type, full, meta){
            var context = [{
                title:"复制",
                markClass:"object-copy",
                iconFont:"&#xe6ea;"
            },{
                title:"编辑",
                markClass:"object-edit",
                iconFont:"&#xe6df;"
            },{
                title:"删除",
                markClass:"object-del",
                iconFont:"&#xe6e2;"
            }];
            return btnIconTemplate(context);
        }
    }];
var settingParams;
var step_element_name;
var eventList = {
    ".object-copy":function(){
        let data = $.extend(true, {}, table.row( $(this).parents('tr') ).data());
        data.id = null;
        step_element_name = 'snippet' == data.type ? data.snippet_name : data.element_name;
        publish.renderParams.editPage.modeFlag = 0;
        layer_show("新增测试步骤", editHtml, editPageWidth, editPageHeight.add, 1, function(layero, index){
            iterObj(data);

            let name = 'snippet' == data.type ? data.snippet_id : data.element_id;

            if ('snippet' == data.type) {
                $('#keyword_id').parents('.row').hide();
                $('#element_id').parents('.row').hide();

                if (GLOBAL_UTILS.stringUtils.isNotBlank(step_element_name)) {
                    $('#snippet_nameText').text(step_element_name + ' [ ID:' + name + ' ]');
                }

                return;
            }


            if (GLOBAL_UTILS.stringUtils.isNotBlank(step_element_name)) {
                $('#element_nameText').text(step_element_name + ' [ ID:' + name + ' ]');
            }
            $('#snippet_id').parents('.row').hide();

            $('#type').val(data.type);
            $('#type').trigger('change');
            $('#keyword_id').val(data.keyword_id);
            $('#keyword_id').trigger('change');

            $('#step_name').val(data.step_name);

        });
        publish.init();
    },
    "#add-object":function(){
        publish.renderParams.editPage.modeFlag = 0;
        layer_show("新增测试步骤", editHtml, editPageWidth, 580, 1, function(layero, index) {
            $("#case_id").val(caseId);
            $('#snippet_id').parents('.row').hide();

            $("#step_name").val('测试步骤' + GLOBAL_UTILS.dateUtils.dateFormat(new Date(), 'yyyyMMddHHmmss'));
        });
        publish.init();
    },
    //选择元素对象
    "#choose-element":function(){
        let elementId = $('#element_id').val();
        let url = 'chooseElement.html?callback=chooseElementCallback';
        if (GLOBAL_UTILS.stringUtils.isNotBlank(elementId)) {
            url += '&elementId=' + elementId;
        }
        layer_show('选择元素对象', url, null, null, 2);
    },
    //清除以选择的元素对象
    '#clear-choose-element':function(){
        step_element_name = null;

        $('#element_id').val('');
        $('#element_nameText').text('');

        layer.msg('已清除', {icon: 1, time:1400});
    },
    //选择用例片段
    "#choose-snippet":function(){
        layer_show('选择用例片段', 'chooseCase.html?callback=chooseSnippetCallback&case_type=snippet', null, null, 2)
    },
    //清除以选择的用例片段
    '#clear-choose-snippet':function(){
        step_element_name = null;

        $('#snippet_id').val('');
        $('#snippet_nameText').text('');

        layer.msg('已清除', {icon: 1, time:1400});
    },
    '#keyword_id': {
        'change': function(){
            if ($('#type').val() == 'web_ui') {
                if (GLOBAL_UTILS.stringUtils.isNotBlank($('#element_id').val())) {
                    $("#step_name").val($('#keyword_id').find('option:selected').text() + '-' + step_element_name);
                }
            } else if ($('#type').val() == 'function') {
                $("#step_name").val($('#keyword_id').find('option:selected').text())
            }
        }
    },
    '#snippet_nameText': {
        'DOMNodeInserted': function(){
            if (step_element_name == null) {
                $("#step_name").val('执行用例片段');
            } else {
                $("#step_name").val('执行用例片段' + '-' + step_element_name);
            }
        }
    },
    '#element_nameText':{
        'DOMNodeInserted': function(){
            if (GLOBAL_UTILS.stringUtils.isNotBlank($('#keyword_id').val())) {
                if (step_element_name == null) {
                    $("#step_name").val($('#keyword_id').find('option:selected').text());
                } else {
                    $("#step_name").val($('#keyword_id').find('option:selected').text() + '-' + step_element_name);
                }
            }
        }
    },
    '#type': {
        'change': function(){
            let elId;
            let newType = $(this).val();
            //单独处理用例片段类型
            if ('snippet' == newType) {
                $('#keyword_id').parents('.row').hide();
                $('#element_id').parents('.row').hide();
                $('#snippet_id').parents('.row').show();

                elId = $('#snippet_id').val();
                if (GLOBAL_UTILS.stringUtils.isNotBlank(elId)) {
                    $("#step_name").val('执行用例片段' + '-' + $("#snippet_nameText").text().replace(/(\[.*\])/, '').trim());
                }

                return;
            }

            $('#keyword_id').parents('.row').show();
            $('#element_id').parents('.row').show();
            $('#snippet_id').parents('.row').hide();
            elId = $('#element_id').val();

            let options = '';
            if (DICT_CONFIG.keyword[newType] != null) {
                $.each(DICT_CONFIG.keyword[newType], function(i, n){
                    options = options + '<option value="' + n.id + '">' + n.cn_name + '</option>';
                });
            }

            $('#keyword_id').html(options);

            if (newType == 'function') {
                $("#step_name").val($('#keyword_id').find('option:selected').text())
            } else {
                if (GLOBAL_UTILS.stringUtils.isNotBlank(elId)
                    && GLOBAL_UTILS.stringUtils.isNotBlank($('#keyword_id').val())) {
                    $("#step_name").val($('#keyword_id').find('option:selected').text() + '-'
                        + $("#element_nameText").text().replace(/(\[.*\])/, '').trim());
                }
            }



            //getSettingParams(newType, elId, $('#keyword_id').val());
        }
    },
    "#batch-op":function(){
        layer.confirm(
            '请选择你需要进行的批量操作:',
            {
                title:'批量操作',
                btn:['删除', '取消'],
                shadeClose:true,
            },function(index){
                layer.close(index);
                batchOp($(".selectStep:checked"), REQUEST_URL.WEB_CASE_STEP.delStep, "删除", null, "id", {case_id:caseId});
            },function(index){
                layer.close(index);
            });
    },
    ".object-edit":function(){
        var data = table.row( $(this).parents('tr') ).data();
        publish.renderParams.editPage.modeFlag = 1;
        publish.renderParams.editPage.objId = data.id;
        publish.renderParams.editPage.currentObj = data;
        layer_show("编辑步骤信息", editHtml, editPageWidth, editPageHeight.edit, 1);
        publish.init();
    },
    ".object-del":function(){
        var data = table.row( $(this).parents('tr') ).data();
        opObj("确认要删除此测试步骤吗？", REQUEST_URL.WEB_CASE_STEP.delStep, {id:data.id}, this, "删除成功!");
    },
    //配置用例片段
    '#setting-snippet':function() {
        if (GLOBAL_UTILS.stringUtils.isBlank($('#snippet_id').val())) {
            layer.msg('请先选择一个用例片段再进行配置!', {time: 1600});
            return false;
        }

        let snippetSetting = $('#snippet_setting').val();
        let setting = {};
        if (GLOBAL_UTILS.stringUtils.isNotBlank(snippetSetting)) {
            setting = JSON.parse(snippetSetting);
        }
        layer_show('配置用例片段', templates['tdp-step-snippet-setting'](setting), 540, 240, 1, function(layero, index){
            $(layero).find('#exitCondition').val(setting['exitCondition'] || '');
            $(layero).find('#errorStillRun').val(setting['errorStillRun'] || 'false');
        }, function(index, layero){
            setting['executeCount'] = $(layero).find('#executeCount').val();
            setting['exitCondition'] = $(layero).find('#exitCondition').val();
            setting['errorStillRun'] = $(layero).find('#errorStillRun').val();

            $('#snippet_setting').val(JSON.stringify(setting));
            layer.msg('配置已更新!', {icon: 1, time: 1500});
        }, null, {shadeClose: false});
    },
    '.setting-default-data':function(){
        let data = table.row( $(this).parents('tr') ).data();
        if (GLOBAL_UTILS.stringUtils.isBlank(data.default_data)
            || !GLOBAL_UTILS.jsonUtils.isJsonStr(data.default_data)) {
            data.default_data = "{}";
        }

        getSettingParams(data.type, data.type == 'snippet' ? data.snippet_id : data.element_id, data.keyword_id, "test_data");

        layer_show('配置测试数据', templates['web-test-config-view']({default_data: JSON.parse(data.default_data), settingType: 'default_data'}), 580, 450, 1, function(layero, index){
            $(layero).find('#update-web-test-config').one('click', function(){  //更新配置
                let configObj = {};
                $("#web-test-config-variables").children('.row').each(function(i){
                    let key = $(this).find('input').eq(0).val();
                    let value = $(this).find('input').eq(1).val();
                    if (strIsNotEmpty(key) && strIsNotEmpty(value)) {
                        configObj[key] = value;
                    }
                });
                layer.close(index);
                if (!CompareJsonObj(configObj, JSON.parse(data.default_data))) {
                    GLOBAL_UTILS.ajaxUtils.ajaxPost(REQUEST_URL.WEB_CASE_STEP.updateData, {id:data.id, default_data:JSON.stringify(configObj)}, function(json) {
                        layer.msg('更新成功!', {icon:1, time: 1500});
                        refreshTable();
                    });
                } else {
                    layer.msg('未有改动!', {icon:5, time:1800});
                }
            });
        }, null, null, {shadeClose:false, offset: '10px'});
    },
    '#setting-default-data': function () {
        let data = $('#default_data').val();
        if (GLOBAL_UTILS.stringUtils.isBlank(data)
            || !GLOBAL_UTILS.jsonUtils.isJsonStr(data)) {
            data = "{}";
        }

        getSettingParams($('#type').val(), $('#type').val() == 'snippet' ? $('#snippet_id').val() : $('#element_id').val()
            , $('#keyword_id').val() , "test_data");

        layer_show('配置测试数据', templates['web-test-config-view']({default_data: JSON.parse(data), settingType: 'default_data'}), 580, 450, 1, function(layero, index){
            $(layero).find('#update-web-test-config').one('click', function(){  //更新配置
                let configObj = {};
                $("#web-test-config-variables").children('.row').each(function(i){
                    let key = $(this).find('input').eq(0).val();
                    let value = $(this).find('input').eq(1).val();
                    if (strIsNotEmpty(key) && strIsNotEmpty(value)) {
                        configObj[key] = value;
                    }
                });
                layer.close(index);
                $('#default_data').val(JSON.stringify(configObj));
                layer.msg('配置成功！', {icon: 1, time: 1500});
            });
        }, null, null, {shadeClose:false});

    },
    '#setting-export-data': function(){
        let data = $('#export_data').val();
        if (GLOBAL_UTILS.stringUtils.isBlank(data)
            || !GLOBAL_UTILS.jsonUtils.isJsonStr(data)) {
            data = "{}";
        }

        layer_show('配置输出数据', templates['web-test-config-view']({default_data: JSON.parse(data)}), 580, 450, 1, function(layero, index){
            $(layero).find('#update-web-test-config').one('click', function(){  //更新配置
                let configObj = {};
                $("#web-test-config-variables").children('.row').each(function(i){
                    let key = $(this).find('input').eq(0).val();
                    let value = $(this).find('input').eq(1).val();
                    if (strIsNotEmpty(key) && strIsNotEmpty(value)) {
                        configObj[key] = value;
                    }
                });
                layer.close(index);
                $('#export_data').val(JSON.stringify(configObj));
                layer.msg('配置成功！', {icon: 1, time: 1500});
            });
        }, null, null, {shadeClose:false});
    },
    '.setting-export-data':function(){
        let data = table.row( $(this).parents('tr') ).data();
        if (GLOBAL_UTILS.stringUtils.isBlank(data.export_data)
            || !GLOBAL_UTILS.jsonUtils.isJsonStr(data.export_data)) {
            data.export_data = "{}";
        }
        layer_show('配置输出数据', templates['web-test-config-view']({default_data: JSON.parse(data.export_data)}), 580, 450, 1, function(layero, index){
            $(layero).find('#update-web-test-config').one('click', function(){  //更新配置
                let configObj = {};
                $("#web-test-config-variables").children('.row').each(function(i){
                    let key = $(this).find('input').eq(0).val();
                    let value = $(this).find('input').eq(1).val();
                    if (strIsNotEmpty(key) && strIsNotEmpty(value)) {
                        configObj[key] = value;
                    }
                });
                layer.close(index);
                if (!CompareJsonObj(configObj, JSON.parse(data.export_data))) {
                    GLOBAL_UTILS.ajaxUtils.ajaxPost(REQUEST_URL.WEB_CASE_STEP.updateData, {id:data.id, export_data:JSON.stringify(configObj)}, function(json) {
                        layer.msg('更新成功!', {icon:1, time: 1500});
                        refreshTable();
                    });
                } else {
                    layer.msg('未有改动!', {icon:5, time:1800});
                }
            });
        }, null, null, {shadeClose:false, offset: '10px'});
    },
    '#setting-expected-result':function(){
        let data = $('#expected_result').val();
        if (GLOBAL_UTILS.stringUtils.isBlank(data)
            || !GLOBAL_UTILS.jsonUtils.isJsonStr(data)) {
            data = "{}";
        }

        getSettingParams($('#type').val(), $('#type').val() == 'snippet' ? $('#snippet_id').val() : $('#element_id').val()
            , $('#keyword_id').val() , "expect");

        layer_show('配置预期结果', templates['web-test-config-view']({default_data: JSON.parse(data), settingType: 'default_data'}), 580, 450, 1, function(layero, index){
            $(layero).find('#update-web-test-config').one('click', function(){  //更新配置
                let configObj = {};
                $("#web-test-config-variables").children('.row').each(function(i){
                    let key = $(this).find('input').eq(0).val();
                    let value = $(this).find('input').eq(1).val();
                    if (strIsNotEmpty(key) && strIsNotEmpty(value)) {
                        configObj[key] = value;
                    }
                });
                layer.close(index);
                $('#expected_result').val(JSON.stringify(configObj));
                layer.msg('配置成功！', {icon: 1, time: 1500});
            });
        }, null, null, {shadeClose:false});
    },
    '.setting-expected-result':function(){
        let data = table.row( $(this).parents('tr') ).data();
        if (GLOBAL_UTILS.stringUtils.isBlank(data.expected_result)
            || !GLOBAL_UTILS.jsonUtils.isJsonStr(data.expected_result)) {
            data.expected_result = "{}";
        }

        getSettingParams(data.type, data.type == 'snippet' ? data.snippet_id : data.element_id, data.keyword_id, "expect");

        layer_show('配置预期结果', templates['web-test-config-view']({default_data: JSON.parse(data.expected_result), settingType: 'default_data'}), 580, 450, 1, function(layero, index){
            $(layero).find('#update-web-test-config').one('click', function(){  //更新配置
                let configObj = {};
                $("#web-test-config-variables").children('.row').each(function(i){
                    let key = $(this).find('input').eq(0).val();
                    let value = $(this).find('input').eq(1).val();
                    if (strIsNotEmpty(key) && strIsNotEmpty(value)) {
                        configObj[key] = value;
                    }
                });
                layer.close(index);
                if (!CompareJsonObj(configObj, JSON.parse(data.expected_result))) {
                    GLOBAL_UTILS.ajaxUtils.ajaxPost(REQUEST_URL.WEB_CASE_STEP.updateData, {id:data.id, expected_result:JSON.stringify(configObj)}, function(json) {
                        layer.msg('更新成功!', {icon:1, time: 1500});
                        refreshTable();
                    });
                } else {
                    layer.msg('未有改动!', {icon:5, time:1800});
                }
            });
        }, null, null, {shadeClose:false, offset: '10px'});
    },
    "#web-test-config-add-variable":function(){//增加一对key-value
        let settingType = $('#settingType').val();

        if (settingType == 'default_data' && settingParams != null && settingParams.length > 0) {
            showSelectBox(settingParams, 'value', 'key', function(id, obj, index){
                doit(obj.value);
                layer.close(index);
            }, '选择可配置数据');
        } else {
            doit('');
        }
    },
    "#web-test-config-clear-all-varibale":function(){//清除全部
        layer.confirm('确认删除下列全部的测试数据吗？', {title:'警告'}, function(index){
            $("#web-test-config-variables").html('');
            layer.msg('全部删除成功!', {icon:1, time:1800});
            layer.close(index);
        });
    },
    "#web-test-config-variables a":function(){//删除该项
        var that = this;
        layer.confirm('确认删除该项测试数据吗?', {title:'警告'}, function(index) {
            $(that).parent('.formControls').parent('.row').remove();
            layer.msg('删除成功!', {icon:1, time:1800});
            layer.close(index);
        });
    },
    "#setting-step-order":function() {//步骤排序
        GLOBAL_UTILS.ajaxUtils.ajaxGet(REQUEST_URL.WEB_CASE_STEP.listStep + "?case_id=" + caseId, function (data) {
            if (data.data.length < 2) {
                layer.msg('测试步骤太少了,再添加几个吧!', {time:1500});
                return false;
            }
            let heignt = 140 + 40 * data.data.length;
            let sortableHtml = templates["sort-case-steps"](data.data);

            layer_show("步骤执行排序-请手动拖拽", sortableHtml, 680, heignt, 1, function (layero, index) {
                $(layero).spinModal();
                var sortObj = new Sortable(document.getElementById('case-steps'), {
                    animation: 150
                });
                var orderArr = [];
                for (var i = 1;i <= data.data.length;i++){
                    orderArr.push(data.data[i - 1]['id'] + "");
                }
                sortObj.sort(orderArr);
                $("#save-case-steps-sort").click(function () {//保存提交到后台并关闭弹出层
                    if (JSON.stringify(sortObj.toArray()) == JSON.stringify(orderArr)) {//没有改动
                        layer.msg('未作改动!', {time:1500});
                        layer.close(index);
                        return false;
                    }

                    GLOBAL_UTILS.ajaxUtils.ajaxPost(REQUEST_URL.WEB_CASE_STEP.sortStep, sortObj.toArray(), function(json){
                        layer.msg("保存排序成功!", {icon:1, time:1800})
                        refreshTable();
                        layer.close(index);
                    });
                });
                $("#reset-case-steps-sort").click(function () {//重置
                    sortObj.sort(orderArr);
                });
                $(layero).spinModal(false);
            }, null, function () {
                $("#save-case-steps-sort").unbind('click');
                $("#reset-case-steps-sor").unbind('click');
            }, {
                offset: '18px'
            });
        });
    }
};

var caseId;
var mySetting = {
    eventList:eventList,
    templateCallBack:function(df){
        caseId = GetQueryString("case_id");
        publish.renderParams.listPage.listUrl = REQUEST_URL.WEB_CASE_STEP.listStep + "?case_id=" + caseId;

        df.resolve();
    },
    listPage:{
        listUrl:REQUEST_URL.WEB_CASE_STEP.listStep,
        tableObj:".table-sort",
        columnsSetting:columnsSetting,
        columnsJson:[0, 8, 9, 10, 14],
        dtOtherSetting:{
            serverSide:false,
            order: [[ 3, 'asc' ]]
        }
    },
    editPage:{
        editUrl:REQUEST_URL.WEB_CASE_STEP.editStep,
        getUrl:REQUEST_URL.WEB_CASE_STEP.getStep,
        rules:{
            step_name:{
                required:true,
                minlength:2,
                maxlength:255
            },
            seq_num:{
                digits:true
            }
        },
        renderCallback: function(obj){
            if ('snippet' == obj.type) {
                $('#keyword_id').parents('.row').hide();
                $('#element_id').parents('.row').hide();

                step_element_name = obj.snippet_name;
                if (GLOBAL_UTILS.stringUtils.isNotBlank(obj.snippet_name)) {
                    $('#snippet_nameText').text(obj.snippet_name + ' [ID:' + obj.snippet_id + ']');
                }

                return;
            }

            $('#snippet_id').parents('.row').hide();

            //$('#type').val(obj.type);
            //$('#type').trigger('change');

            //$('#keyword_id').val(obj.keyword_id);
            //$('#keyword_id').trigger('change');

            step_element_name = obj.element_name;
            if (GLOBAL_UTILS.stringUtils.isNotBlank(obj.element_name)) {
                $('#element_nameText').text(obj.element_name + ' [ID:' + obj.element_id + ']');
            }

            $("#step_name").val(obj.step_name);

        }
    },
    templateParams:templateParams
};

$(function(){
    publish.renderParams = $.extend(true,publish.renderParams,mySetting);
    publish.init();
});


function chooseElementCallback(obj) {
    step_element_name = obj.element_name;
    $('#element_nameText').text(obj.element_name + ' [ID:' + obj.id + ']');
    $('#element_id').val(obj.id);
    layer.msg('选择成功', {icon: 1, time:1400});
}


function chooseSnippetCallback(obj) {
    step_element_name = obj.case_title;
    $('#snippet_nameText').text(obj.case_title + ' [ID:' + obj.id + ']');
    $('#snippet_id').val(obj.id);
    layer.msg('选择成功', {icon: 1, time:1400});
}

function doit(defaultKey){
    $("#web-test-config-variables").append('<div class="row cl"><div class="form-label col-xs-5 col-sm-5">'
        + '<input type="text" class="input-text radius" value="' + defaultKey + '"></div>'
        + '<div class="formControls col-xs-5 col-sm-5"><input type="text" class="input-text radius"></div>'
        + '<div class="formControls col-xs-2 col-sm-2"><a class="btn btn-default radius">'
        + '<i class="Hui-iconfont">&#xe60b;</i></a></div></div>');
}

function getSettingParams(type, element_id, keyword_id, param_type) {
    settingParams = [];
    if (GLOBAL_UTILS.stringUtils.isBlank(element_id)) {
        element_id = '';
    }

    let url = '';
    url = REQUEST_URL.WEB_CASE_STEP.queryParams + '&element_id=' + element_id + '&step_type='
        + type + '&keyword_id=' + keyword_id + '&param_type=' + param_type;


    GLOBAL_UTILS.ajaxUtils.ajaxGet(url, function(json){
        if (json.data.length > 0) {
            settingParams.push({
                key: '[自定义]',
                value: ''
            });
            $.each(json.data, function(i, n){
                settingParams.push({
                    key: n,
                    value: n
                })
            });
        }
    });
}